<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <script src="js/享元模式1.js"></script>
    <script>
        // Sample usage:
        // testFlyweight()
        function testFlyweight() {
            // The flavors ordered.
            var flavors = new CoffeeFlavor(),
                // The tables for the orders.
                tables = new CoffeeOrderContext(),
                // Number of orders made
                ordersMade = 0,
                // The CoffeeFlavorFactory instance
                flavorFactory;

            function takeOrders(flavorIn, table) {
                flavors[ordersMade] = flavorFactory.getCoffeeFlavor(flavorIn);
                tables[ordersMade++] = new CoffeeOrderContext(table);
            }

            flavorFactory = new CoffeeFlavorFactory();
            takeOrders("Cappuccino", 2);
            takeOrders("Cappuccino", 2);
            takeOrders("Frappe", 1);
            takeOrders("Frappe", 1);
            takeOrders("Xpresso", 1);
            takeOrders("Frappe", 897);
            takeOrders("Cappuccino", 97);
            takeOrders("Cappuccino", 97);
            takeOrders("Frappe", 3);
            takeOrders("Xpresso", 3);
            takeOrders("Cappuccino", 3);
            takeOrders("Xpresso", 96);
            takeOrders("Frappe", 552);
            takeOrders("Cappuccino", 121);
            takeOrders("Xpresso", 121);
            for (var i = 0; i < ordersMade; ++i) {
                flavors[i].serveCoffee(tables[i]);
            }
            console.log(" ");
            console.log("total CoffeeFlavor objects made: " + flavorFactory.getTotalCoffeeFlavorsMade());
        }
        testFlyweight();
//        <
//        span
//        style = "line-height:1.5;font-family:'sans serif', tahoma, verdana, helvetica;font-size:10pt;" > < / span >
    </script>
</body>
</html>